# -- coding: utf-8 --


class Solution:
    def sortColors(self, nums):
        """
        :type nums: List[int]
        :rtype: void Do not return anything, modify nums in-place instead.
        """
        left = 0
        right = len(nums) - 1
        mid = 0
        while mid <= right:
            if nums[mid] == 0:
                nums[mid] = nums[left]  # 交换 并不改变
                nums[left] = 0
                left += 1
                mid += 1
            elif nums[mid] == 1:
                mid += 1
            else:
                nums[mid] = nums[right]
                nums[right] = 2
                right -= 1
        return nums


test = Solution()
print(test.sortColors([2, 0, 2, 1, 1, 0]))

